//
//  DKHomeHeadAuthorizedView.m
//  DanKU
//
//  Created by 吴斌 on 2023/10/6.
//

#import "DKHomeHeadAuthorizedView.h"
#import "DKHomeAuthorizedCircleView.h"
#import "DKHomeTranFailView.h"
#import "DKHomeHelperAlertView.h"
@interface DKHomeHeadAuthorizedView()
@property (nonatomic, strong)UIImageView* dk_HomeBgImgView;
@property (nonatomic, strong)DKHomeAuthorizedCircleView * dk_HomeAuthorizedCircleView;
@property (nonatomic, strong)DKHomeTranFailView * dk_HomeTranFailView;
@end
@implementation DKHomeHeadAuthorizedView
-(instancetype)init{
    if(self == [super init]){
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    WeakSelf(self)
    self.dk_HomeBgImgView = [[UIImageView alloc] init];
    self.dk_HomeBgImgView.userInteractionEnabled = YES;
    self.dk_HomeBgImgView.image = DK_GetImage(@"dk_HomeUnauthorizeHeadBg");
    [self addSubview:self.dk_HomeBgImgView];
    [self.dk_HomeBgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    //welcome
    UILabel *dk_welcomeLab = [[UILabel alloc] init];
    dk_welcomeLab.textColor = DK_Hex(@"#FFFFFF");
    dk_welcomeLab.font = DK_FONT_Semibold(30);
    dk_welcomeLab.text = @"Welcome！";
    [self addSubview:dk_welcomeLab];
    [dk_welcomeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.top.equalTo(@(DK_IsWidthScale(49)+DK_SafeAreaTop));
        make.height.equalTo(@(DK_IsWidthScale(42)));
    }];
    self.dk_HomeAuthorizedCircleView = [[DKHomeAuthorizedCircleView alloc] init];
    [self addSubview:self.dk_HomeAuthorizedCircleView];
    [self.dk_HomeAuthorizedCircleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(15)));
        make.right.equalTo(@(-DK_IsWidthScale(15)));
        make.top.equalTo(dk_welcomeLab.mas_bottom);
        make.height.equalTo(@(DK_IsWidthScale(200)));
    }];
    UIButton * dk_HomeAuthorizedHelperBtn = [[UIButton alloc] init];
    [dk_HomeAuthorizedHelperBtn setBackgroundImage:[UIImage imageNamed:@"dk_HomeHelpIcon"] forState:UIControlStateNormal];
    [dk_HomeAuthorizedHelperBtn addTarget:self action:@selector(homeHelper) forControlEvents:UIControlEventTouchUpInside];
    [self.dk_HomeAuthorizedCircleView addSubview:dk_HomeAuthorizedHelperBtn];
    [dk_HomeAuthorizedHelperBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(DK_IsWidthScale(20)));
        make.right.equalTo(@(-DK_IsWidthScale(20)));
        make.width.equalTo(@(DK_IsWidthScale(15)));
        make.height.equalTo(@(DK_IsWidthScale(15)));
    }];
    
    self.dk_HomeTranFailView = [[DKHomeTranFailView alloc] init];
    self.dk_HomeTranFailView.hidden = YES;
    [self addSubview:self.dk_HomeTranFailView];
    [self.dk_HomeTranFailView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(15)));
        make.right.equalTo(@(-DK_IsWidthScale(15)));
        make.top.equalTo(self.dk_HomeAuthorizedCircleView.mas_bottom).offset(DK_IsWidthScale(9));
        make.bottom.equalTo(@(-DK_IsWidthScale(17)));
    }];
    self.dk_HomeTranFailView.HomeTranFailBlock = ^{
        if(weakSelf.HomeTranFailBlock){
            weakSelf.HomeTranFailBlock();
        }
    };
}
-(void)setDk_UserLoanStatusMdl:(DKUserLoanStatusModel *)dk_UserLoanStatusMdl{
    _dk_UserLoanStatusMdl = dk_UserLoanStatusMdl;
    if(_dk_UserLoanStatusMdl.loanFail){//放款失败
        self.dk_HomeTranFailView.hidden = NO;
        self.dk_HomeBgImgView.image = DK_GetImage(@"dk_HomeUnauthorizeBigHeadBg");
        [self.dk_HomeTranFailView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.dk_HomeAuthorizedCircleView.mas_bottom).offset(DK_IsWidthScale(9));
            make.bottom.equalTo(@(-DK_IsWidthScale(17)));
        }];
    }else{
        self.dk_HomeTranFailView.hidden = YES;
        self.dk_HomeBgImgView.image = DK_GetImage(@"dk_HomeUnauthorizeHeadBg");
        [self.dk_HomeTranFailView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.dk_HomeAuthorizedCircleView.mas_bottom).offset(DK_IsWidthScale(0));
            make.bottom.equalTo(@(-DK_IsWidthScale(0)));
        }];
    }
}
- (void)homeHelper{
    [DKHomeHelperAlertView dk_ShowHomeHelperAlertView:^{
            
    }];
}
- (void)updataHomeHeadData{
    [self.dk_HomeAuthorizedCircleView updataHomeHeadData];
}
@end
